﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HIDTOOL
{
    class HexDecProcess
    {
        public static bool InputIsDec(KeyPressEventArgs e)      //输入 0~9或删除，返回true
        {
            if (e.KeyChar == '\b')//这是允许输入退格键  
                return true;
            if (e.KeyChar >= '0' && e.KeyChar <= '9')
                return true;
            if (e.KeyChar == 0x0016)    //ctrl + V
                return true;
            if (e.KeyChar == 0x0003)    //ctrl + C
                return true;
            return false;
        }

        public static bool InputIsHex(KeyPressEventArgs e)  //输入 0~9 或 a~f 或 A~F 或 删除，返回true
        {
            if (e.KeyChar == '\b')//这是允许输入退格键  
                return true;
            if (e.KeyChar >= '0' && e.KeyChar <= '9')          
                return true;
            if (e.KeyChar >= 'a' && e.KeyChar <= 'f')
                return true;
            if (e.KeyChar >= 'A' && e.KeyChar <= 'F')
                return true;
            if (e.KeyChar == 0x0016)    //ctrl + V
                return true;
            if (e.KeyChar == 0x0003)    //ctrl + C
                return true;
            return false;       //执行这一句，输入被取消                                       
        }

        public static bool InputIsMAC(KeyPressEventArgs e)  //输入 0~9 或 a~f 或 A~F 或 删除 或 冒号，返回true
        {
            if (e.KeyChar == '\b')//这是允许输入退格键  
                return true;
            if (e.KeyChar >= '0' && e.KeyChar <= '9')          
                return true;
            if (e.KeyChar >= 'a' && e.KeyChar <= 'f')
                return true;
            if (e.KeyChar >= 'A' && e.KeyChar <= 'F')
                return true;
            if (e.KeyChar == ':')
                return true;
            if (e.KeyChar == 0x0016)    //ctrl + V
                return true;
            return false;       //执行这一句，输入被取消                                       
        }
        public static string Dec2Hex_TextBox(string inputDec)   //十进制字符串 转换成十六进制字符串
        {
            string OutputHex = "";
            if (inputDec != "")
            { 
                UInt32 input = 0;
                input = Convert.ToUInt32(inputDec);
                OutputHex = String.Format("{0:X}", input);
            }
            return OutputHex;
        }

        public static string Hex2Dec_TextBox(string inputHex)
        {
            string OutputDec = "";
            if (inputHex != "")
            {
                UInt32 input = 0;
                input = Convert.ToUInt32(inputHex, 16);//16:HEX
                OutputDec = String.Format("{0:D}", input);
            }
            return OutputDec;
        }
    }
}











